
export default {
    namespaced: true,
    state: {
        tabIndex: 1,
        editableTabsValue: '首页',
        editableTabs: [
            {
                title: '首页',
                name: '首页',
                comName: 'Home'
            }
        ]
    },
    mutations: {
        addTab (state, tabs) {
            let flag = true
            state.editableTabs.forEach((tab, index) => {
                if (tab.name === tabs.name) {
                    state.editableTabsValue = tab.name
                    flag = false
                }
            })
            if (flag) {
                state.tabIndex += 1
                state.editableTabsValue = tabs.name
                state.editableTabs.push(tabs)
            }
        },
        delTab (state, tabName) {
            const tabs = state.editableTabs
            let activeName = state.editableTabsValue
            if (state.editableTabs.length <= 1) return
            if (activeName === tabName) {
                tabs.forEach((tab, index) => {
                    if (tab.name === tabName) {
                        const nextTab = tabs[index + 1] || tabs[index -1]
                        if (nextTab) {
                            activeName = nextTab.name
                        }
                    }
                })
            }

            state.editableTabsValue = activeName
            state.editableTabs = tabs.filter((tab) => tab.name !== tabName)
        }
    },
    actions: {
    },
    modules: {
    }
}